home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5397 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!milyng
  3. From: mikael@pobox.com (Mikael Lyngvig)
  4. Subject: Re: Escape Sequences in c++
  5. Message-ID: <milyngDM8JFq.LKv@netcom.com>
  6. Sender: milyng@netcom9.netcom.com
  7. Organization: Hacker's Paradise, Inc.
  8. X-Newsreader: WinVN 0.99.7
  9. References: <3113aa29.14180305@news.flex.net>
  10. Date: Sun, 4 Feb 1996 05:04:37 GMT
  11.  
  12. In article <3113aa29.14180305@news.flex.net>, Awitas@flex.net says...
  13.  
  14. >        Does anyone know how to use the Ansi.sys escape sequences in
  15. >c++? Specifically the cursor-control sequences. Any help would be
  16. >greatly appreciated. 
  17.  
  18. Assuming you have ANSI.SYS installed, you can just write them to 'stdout' 
  19. (the default output device when you use C's standard I/O library):
  20.  
  21. #include <stdio.h>
  22.  
  23. int main(int argc, const char *argv[])
  24. {
  25.    FILE *pOutput;
  26.  
  27.    ...
  28.  
  29.    printf("\x1B[1;33;44m%s: %s\x1B[0m\n", DateStr, EventStr);
  30.  
  31.    pOutput = stdout;
  32.    fprintf(pOutput, "\x1B[1;33;44m%s: %s\x1B[0m\n", DateStr, EventStr);
  33. }
  34.  
  35. I think the escape sequence shown displays the current date and a so-called 
  36. event (a string) using white ink on blue paper (mm.dd.yy: string).  \x1B is 
  37. the Escape character that marks the beginning of an ANSI escape sequence and 
  38. so on.  The example mixes hexadecimal C escape sequences (\xNN) with clear 
  39. text characters ([), but it would probably be a good idea to isolate it 
  40. somehow and have specific functions such as "SetInkColor(WHITE); 
  41. SetPaperColor(BLUE);" etc., so you can easily change it to not use ANSI later 
  42. on (when you discover that very few systems support ANSI and not all users 
  43. have ANSI.SYS installed :).
  44.  
  45. This is code from a program I wrote years back, but it illustrates the 
  46. concept; the two statements are functionally identical (I recommend using the 
  47. second method because it gives you the option of dumping the stuff to a file 
  48. for debugging purposes etc.).
  49.  
  50.  
  51. Mikael
  52.  
  53.